package org.atguigu.mapper.impl;

import org.apache.ibatis.session.SqlSession;
import org.atguigu.entity.Student;
import org.atguigu.mapper.StudentMapper;
import org.atguigu.utils.SqlSessionUtil;

import java.util.Collections;
import java.util.List;

/*
对于接口实现类所在的包名，必须叫impl
实现类的命名，必须是接口名+Impl
 */
public class StudentMapperImpl implements StudentMapper {
    @Override
    public Student getById(String id) {
        SqlSession session = SqlSessionUtil.getSqlSession();
        Student s = session.selectOne("abc.getById", id);
        SqlSessionUtil.close(session);
        return s;
    }

    @Override
    public List<Student> getAll() {
        SqlSession session = SqlSessionUtil.getSqlSession();
        List<Student> list = session.selectList("abc.getAll");
        SqlSessionUtil.close(session);
        return list;
    }

    @Override
    public void insert(Student s) {
        SqlSession session = SqlSessionUtil.getSqlSession();
        session.insert("abc.insert", s);
        session.commit();
        SqlSessionUtil.close(session);
    }

    @Override
    public void update(Student s) {
        SqlSession session = SqlSessionUtil.getSqlSession();
        session.update("abc.update", s);
        session.commit();
        SqlSessionUtil.close(session);
    }

    @Override
    public void delete(String id) {
        SqlSession session = SqlSessionUtil.getSqlSession();
        session.delete("abc.delete", id);
        session.commit();
        SqlSessionUtil.close(session);
    }
}
